class Greeter {
  greeting: string;
  constructor(message: string) {
    this.greeting = message;
  }
  greet() {
    return "Hello, " + this.greeting;
  }
}
let greeter = new Greeter("world");

class Parent {
  static myMethod(msg: string) {
    console.log("static", msg);
  }
  myMethod(msg: string) {
    console.log("instance", msg);
  }
}
class Child extends Parent {
  static myMethod(msg: string) {
    console.log("child static", msg);
    super.myMethod(msg);
  }
  myMethod(msg: string) {
    console.log("child in", msg);
    super.myMethod(msg);
  }
}

// Child.myMethod(1); // static 1
//
// var child = new Child();
// child.myMethod(2); // instance 2

class A {
  x: number;
  y: number = 0;
  constructor(n: number) {
    console.log(n); //=>100;
    this.x = 1001;
  }
  getX() {
    console.log(this.x);
  }
}

class B extends A {
  //=>extends 类似实现原型继承
  constructor() {
    super(100); //=>类似于call的继承：在这里super相当于把A的constructor给执行了，并且让方法中的this是B的实例，super当中传递的实参都是在给A的constructor传递。
    this.y = 200;
  }
  getY() {
    console.log(this.y);
  }
}

// let f = new B();
// f.getX();

class Animal {
  private name: string;
  public constructor(theName: string) {
    this.name = theName;
  }
  public move(distance: number = 0) {
    console.log(`${this.name} moved ${distance}m.`);
  }
}

class Snake extends Animal {
  constructor(name: string) {
    super(name);
  }
  move(dis = 3) {
    console.log("Slithering...");
    super.move(dis);
  }
}
class Horse extends Animal {
  constructor(name: string) {
    super(name);
  }
  move(dis: number = 45) {
    console.log("Galloping...");
    super.move(dis);
  }
}
class Dog extends Animal {
  back() {
    console.log("Back,Back");
  }
}
let dog = new Dog("Dog");
// dog.back()
// dog.move(10)
// dog.back()

let ani = new Animal('Animal the All')
let sam = new Snake("Sammy the Python");
let tom: Animal = new Horse("Tommy the Palomino");

sam.move(1);
tom.move(2);
console.log(ani.move(3))